<template>
    <!-- 菜单项 -->
    <div class="goodsContent">
        <ul class="menu">
<li v-for="item in goods" :key="item.name">
<span>{{item.name}}</span>
</li>
        </ul>
<ol class="list">
    <li v-for="item in goods" :key="item.name">
        <h3>{{ item.name }}</h3>
        <ul class="info">
          <li v-for="food in item.foods" :key="food.name">
            <div class="box">
              <div class="pic">
                <img :src="food.image" alt="" />
              </div>
              <div class="title">
                <h4>{{ food.name }}</h4>
              
                <p class="p5">月售1132份 好评率100%</p>
               <span>￥{{ food.price }}</span> 
              </div>
              <btns :item="food" type="0"></btns>
            </div>
          </li>
        </ul>
      </li>
</ol>
<div class="shopCar" @click="showCar">
      <span>￥：{{ getPrice }}</span>
      <img src="../../components/img/cheche.png" alt="">
      <p class="p1">另需配送费4元</p>
      <p class="p2">￥20元起送</p>
    </div>
   
    </div>
</template>

<script>
// import axios from "axios";
import { mapActions, mapState } from "vuex";
import Btns from "./btns.vue";
export default {
  data() {
    return {
    };
  },
  components: {
    Btns,
  },
  created() {
    this.getGoods();
  },
  computed: {
    //展开运算符
    ...mapState(["goods", "price", "carList",'show']),
    getPrice() {
      let num = 0;
      this.carList.forEach((item) => {
        num += item.price * item.count;
      });
      return num;
    },
  },
  methods: {
    ...mapActions(["getGoods"]),
    add(food) {
      // food.count++;
      if (!food.count) {
        food.count = 1;
      } else {
        food.count++;
      }
      this.$store.commit("setCarList", {
        item: food,
      });
    },
    increment(food) {
      food.count--;
    },
    showCar() {
      this.$store.commit("showCar");
    },
  },
};
</script>

<style lang="less" scoped>
.goodsContent {
  display: flex;
  height: 100%;
  overflow: hidden;
  .menu {
    flex: 0 0 80px;
    //纵向滚动
    overflow-y: scroll;
    li {
      padding: 12px 12px 0 12px;
      height: 42px;
      background: #f3f5f7;
      overflow: hidden;
      span {
        // padding-top: 5px;
        display: block;
        height: 41px;
        font-size: 12px;
        white-space: wrap;
        color: black;
        border-bottom: 1px solid rgba(7, 17, 27, 0.1);
      }
    }
  }
  .list {
    //添加一个高 才能滚动
    height: 100vh;
    // flex:1就是代表均匀分配元素,
    flex: 1 auto;

    overflow-y: scroll;

    h3 {
      border-left: 4px #d9dde1 solid;
      background: #f3f5f7;
      height: 26px;
      line-height: 26px;
      padding-left: 12px;
      color: rgb(147, 153, 159);
      font-weight: 400;
      font-size: 12px;
    }
    .info li {
      padding: 0 18px;
      position: relative;
      .box {
        display: flex;
        padding: 18px 0;
        border-bottom: 1px rgba(1, 17, 27, 0.1) solid;

        .pic img {
          width: 100px;
        }
        .title {
          padding-left: 10px;
        }
      }
    }
  }
  .shopCar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #2b343b;
    height: 46px;
    z-index: 200;
    color: #fff;
  }
}
.title>span{
  color: red;
  font-size: large;
}
.goodsContent btns{
  color: aqua;
}
.shopCar>img{
  position: absolute;
  top: -8px;
  left: 30px;
  width: 48px;
  height: 50px;
}
.shopCar>span{
  position: absolute;
  top:10px;
  left: 80px;
  color: #909195;

}
.p1{
  position: absolute;
  top: 14px;
  left: 150px;
  color: #909195;
  font-size: 12px;
}
.p2{
  position: absolute;
  top: 4px;
 right: 6px;
 color: #909195;
 width: 120px;
 height: 70px;
 background-color: #2b343b;
//  text-align: center;
// margin:0 auto ;
line-height: 40px;
padding-left: 20px;

}
.p5{
  padding-top: 5px;
  color: gray;
  font-size: 12px;
  padding-bottom: 5px;
}
</style>